package com.rattsoftware.client.controllers;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.EventType;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.google.gwt.core.client.GWT;
import com.rattsoftware.client.AppMessages;
import com.rattsoftware.client.webclient;
import com.rattsoftware.client.events.AppEvents;
import com.rattsoftware.client.service.CourseServiceAsync;
import com.rattsoftware.client.service.CourseUnitServiceAsync;
import com.rattsoftware.client.service.UserServiceAsync;
import com.rattsoftware.client.views.NewEditCourseView;

public class NewEditCourseController extends Controller{

	AppMessages appMessages = GWT.create(AppMessages.class);
	
	private CourseServiceAsync courseService;
	private CourseUnitServiceAsync courseUnitService;
	private UserServiceAsync userService;
	private NewEditCourseView newEditCourseView;
	
	public NewEditCourseController() {
        super();
        userService = Registry.get(webclient.USER_SERVICE);
        courseUnitService = Registry.get(webclient.COURSE_UNIT_SERVICE);
        courseService = Registry.get(webclient.COURSE_SERVICE);
        registerEventTypes(AppEvents.NewCourse);
        registerEventTypes(AppEvents.EditCourse);
    }
	
	public void initialize() {
		GWT.log("NewEditCourseController : initialize");
		super.initialize();
		newEditCourseView = new NewEditCourseView(this);
	}
	
	@Override
	public void handleEvent(AppEvent event) {
		GWT.log("NewEditCourseController : handleEvent");
		EventType type = (EventType) event.getType();
		if (type == AppEvents.NewCourse) {
			forwardToView(newEditCourseView, event);
		} else if (type == AppEvents.EditCourse) {
			forwardToView(newEditCourseView, event);
		}
	}

}
